

//创建映像hd，并将所有用户和文件清除
void format(void)
{
    FILE  *fp;
    int   i;
    Inode inode;
    printf("Will be to format filesystem...\n");
    printf("WARNING:ALL DATA ON THIS FILESYSTEM WILL BE LOST!\n");
    printf("Proceed with Format(Y/N)?");
    scanf("%c", &choice);
    gets(temp);
    if((choice == 'y') || (choice == 'Y'))
    {
    if((fp=fopen(image_name, "w+b")) == NULL)
    {
        printf("Can't create file %s\n", image_name);
        exit(-1);
        }
        for(i = 0; i < BLKSIZE; i++)
        fputc('0', fp);
        inode.inum = 0;
        strcpy(inode.file_name, "/");
        inode.type = 'd';
        strcpy(inode.user_name, "all");
        inode.iparent = 0;
        inode.length = 0;
        inode.address[0] = -1;
        inode.address[1] = -1;
        fwrite(&inode, sizeof(Inode), 1, fp);
        inode.inum = -1;
        for(i = 0; i < 31; i++)
            fwrite(&inode, sizeof(Inode), 1, fp);
        for(i = 0; i < BLKNUM*BLKSIZE; i++)
            fputc('\0', fp);
        fclose(fp);
        // 打开文件user.txt
        if((fp=fopen("user.txt", "w+")) == NULL)
        {
        printf("Can't create file %s\n", "user.txt");
            exit(-1);
        }
        fclose(fp);
        printf("Filesystem created successful.Please first login!\n");
    }
    return ;
}